package com.shi.cjmoney;

import android.app.Activity;
import android.content.Intent;

import java.util.ArrayList;
import java.util.List;

public class CJActivityManager {

    public static final String Intent_Name_PakeageName  = "pakeageName";
    public static final String Intent_Name_URL          = "url";
    public static final String Intent_Name_Boolean      = "Boolean";
    public static final String Intent_Name_Number       = "Number";
    public static final String Intent_Name_String       = "String";

    public CJActivityManager() {
    }

    private static CJActivityManager instance = new CJActivityManager();
    private static List<Activity> activityStack = new ArrayList<Activity>();
    public static CJActivityManager getInstance() {
        return instance;
    }

    /**
     * 添加Activity到堆栈
     */
    public void addActivity(Activity activity) {
        if (activityStack == null) {
            activityStack = new ArrayList<Activity>();
        }
        activityStack.add(activity);
    }

    /**
     * 移除指定的Activity
     */
    public void removeActivity(Activity activity) {
        if (activity != null) {
            activityStack.remove(activity);
            activity = null;
        }
    }
    /**
     * 结束所有Activity
     */
    public void finishAllActivity() {
        for (int i = 0, size = activityStack.size(); i < size; i++) {
            if (null != activityStack.get(i)) {
                activityStack.get(i).finish();
            }
        }
        activityStack.clear();
    }

    public static void openActivity(Activity activity,Class activityCalss){
        Intent intent = new Intent(activity, activityCalss);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
    }

    public static void openActivity(Activity activity,Class activityCalss,String packageName){
        Intent intent = new Intent(activity, activityCalss);
        intent.putExtra(Intent_Name_PakeageName,packageName);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
    }

    public static void openActivity_url(Activity activity,Class activityCalss,String url){
        Intent intent = new Intent(activity, activityCalss);
        intent.putExtra(Intent_Name_URL,url);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
    }

    public static void openActivity_boolean(Activity activity,Class activityCalss,boolean isChose){
        Intent intent = new Intent(activity, activityCalss);
        intent.putExtra(Intent_Name_Boolean,isChose);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
    }

    public static void openActivity_number(Activity activity,Class activityCalss,int number){
        Intent intent = new Intent(activity, activityCalss);
        intent.putExtra(Intent_Name_Number,number);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
    }

    public static void openActivity_String(Activity activity,Class activityCalss,String str){
        Intent intent = new Intent(activity, activityCalss);
        intent.putExtra(Intent_Name_String,str);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
    }
}
